package com.ym.medical.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.TransactionDetailsDao;
import com.ym.medical.domain.entity.TransactionDetailsEntity;
import com.ym.medical.domain.param.TransactionDetailsParam;
import com.ym.medical.domain.vo.TdDetailSummaryVO;
import com.ym.medical.domain.vo.TransactionDetailsVo;
import com.ym.medical.enums.PaymentWayEnum;
import com.ym.medical.enums.TransactionDetailsTdTypeEnum;
import com.ym.medical.service.ITransactionDetailsSV;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * ComputerName:LAPTOP-I6GKDIFQ
 * Author:admin
 * Date: 2019-06-14
 * Time: 12:30:48
 * 仅包含充值/提现交易记录服务实现类
 */
@Service
@Transactional( rollbackFor = Exception.class)
public class TransactionDetailsSVImpl extends BaseSVImpl<TransactionDetailsEntity,TransactionDetailsDao> implements ITransactionDetailsSV {

    @Override
    public Long genEmbodyTransactionDetails(Long accId, String otherBillNo, String dfAcc, PaymentWayEnum dfAccType, TransactionDetailsTdTypeEnum ioType,
                                            BigDecimal tdAmount, BigDecimal aftTdAmount, String ioNum) {
        TransactionDetailsEntity transactionDetails = new TransactionDetailsEntity();
        transactionDetails.setAccId(accId);
        transactionDetails.setTdNo(otherBillNo);
        transactionDetails.setDfAcc(dfAcc);
        transactionDetails.setDfAccType(dfAccType.getKey());
        if(TransactionDetailsTdTypeEnum.RECHARGE.getKey().equals(ioType.getKey())){
            transactionDetails.setTdBody("充值");
        }else if (TransactionDetailsTdTypeEnum.EMBODY.getKey().equals(ioType.getKey())){
            transactionDetails.setTdBody("提现");
        }
        transactionDetails.setTdType(ioType.getKey());
        transactionDetails.setTdAmount(tdAmount);
        transactionDetails.setAftTdAmount(aftTdAmount);
        transactionDetails.setPersonalTransactionIoNum(ioNum);
        transactionDetails.setTdTime(new Date());
        this.insert(transactionDetails);
        return transactionDetails.getId();
    }

    @Override
    public PageInfo<TransactionDetailsVo> listDoctorWithdraw(TransactionDetailsParam transactionDetailsModel, int pageNo, int limit) {
        PageHelper.startPage(pageNo,limit);
        List<TransactionDetailsVo> transactionDetailsModels = mapper.listDoctorWithdraw(transactionDetailsModel);
        return new PageInfo<>(transactionDetailsModels);
    }

    @Override
    public PageInfo<TransactionDetailsVo> listTransactionDetail(TransactionDetailsParam transactionDetailsParam, int pageNo, int limit) {
        PageHelper.startPage(pageNo,limit);
        List<TransactionDetailsVo> transactionDetailsModels = mapper.listTransactionDetail(transactionDetailsParam);
        return new PageInfo<>(transactionDetailsModels);
    }

    @Override
    public TdDetailSummaryVO tdDetailSummary(String tdType, Date startTime, Date endTime) {
        return mapper.tdDetailSummary(tdType,startTime,endTime);
    }
}
